define(function () {
    'use strict';

    function ctrl($scope,$stateParams,$ionicHistory,$ionicLoading,$timeout,LocalCacheService,InfoService) {
        $scope.id = $stateParams["id"];

        $scope.$on('$ionicView.loaded', function() {
            init();
        });

        function init(){
            InfoService.getProdFileContent($scope.id).then(function (data){
                var file_content = data.file_content;
                data.file_content = null;
                $scope.agreement = data;

                $ionicLoading.show();
                $timeout(function(){
                    var utel = angular.element(document.querySelector('#file_content'));
                    utel.html(file_content);
                    $ionicLoading.hide();
                }, 600);
            });
        }

        $scope.closeAgreementContent = function(){
            var agreeAgreements = LocalCacheService.get("agreeAgreements");
            if(!agreeAgreements) {
                agreeAgreements = "";
            }
            if(agreeAgreements.indexOf($scope.id) == -1) {
                agreeAgreements += "," + $scope.id;
            }
            LocalCacheService.set("agreeAgreements", agreeAgreements);
            $ionicHistory.goBack();
        }
    }

    ctrl.$inject = ['$scope','$stateParams','$ionicHistory','$ionicLoading','$timeout','LocalCacheService','InfoService'];
    return ctrl;
});
